/**
 * Created with Intellij JDEA
 * Description:
 * User:
 * Date:2022-03-27
 * Time:14:18
 */
public class 把字符串转换成整数 {
    public int StrToInt(String str) {
        if (str.length() == 0) {
            return 0;
        }
        int ret = 0;
        int flag = 1;
        int i = 0;
        if (str.charAt(0) == '+' || str.charAt(0) == '-') {
            i = 1;
            if (str.charAt(0) == '-') {
                flag = -1;
            }
        }
        for (; i < str.length(); i++) {
            if (str.charAt(i) >= '0' && str.charAt(i) <= '9') {
                int tmp = str.charAt(i) - '0';
                ret = ret * 10 + tmp;
            } else {
                return 0;
            }
        }
        return ret * flag;
    }
}
